define(function (require, exports, module) {
    require('seajs-config.js');
    require('bootstrap');
    require('aceElements');
    require('ace');
    // require('bsDialog');
    // require('Kpublic');
    require('less');

    var List = {
        getList: function () {
            /*获取区域、行业、数据范围数据*/
            var fatherBody = $(window.top.document.body);//找到父页面的body对象

            $.ajax({
                url: window.jkconfig.webapiurlv + "analysis/ApplicantSearchParam",
                success: function (data) {
                    if (data.code == 0) {
                        var areaHtml = "", areaNoHtml = "", industryHtml = "", industryUpdate = "", typeHtml = "",
                            dataHtml = "",
                            lawHtml = "";
                        /*遍历data.webAreaInfos,获取区域列表*/
                        if ($("[name=areaId]").length > 0) {
                            areaHtml = '<option value="">全部</option><option value="0">未分类</option>';
                            // areaNoHtml = '';
                            if (data.webAreaInfos.length > 0) {
                                for (var i = 0; i < data.webAreaInfos.length; i++) {
                                    areaHtml += '<option value="' + eval(data.webAreaInfos[i].areaId) + '">' + data.webAreaInfos[i].areaName + '</option>';
                                    // areaNoHtml += '<option value="' + eval(data.webAreaInfos[i].areaId) + '">' + data.webAreaInfos[i].areaName + '</option>';
                                }
                            }
                            $("#areaId").html(areaHtml);
                            var areaId = localStorage["areaId"];
                            if (areaId) {
                                $("#areaId").val(areaId);
                                localStorage.removeItem('areaId')
                            }
                            fatherBody.find("#OareaId").html(areaHtml);
                            fatherBody.find("#areaId").html(areaHtml);
                            fatherBody.find("#mainAreaId").html(areaHtml);
                            localStorage["areaId"] = "";
                        }
                        /*遍历data.WebIndustryInfo,获取行业列表*/
                        if ($(".industryBox").length > 0) {
                            industryHtml = '<span><input type="checkbox"  class="industryAll" checked><label>全部</label></span>' +
                                '<span><input type="checkbox" name="industryId" class="industryItem" value="0" checked><label>未分类</label></span>';
                            if (data.WebIndustryInfo.length > 0) {
                                for (var i = 0; i < data.WebIndustryInfo.length; i++) {
                                    industryHtml += '<span title="' + data.WebIndustryInfo[i].industryName + '">' +
                                        '<input type="checkbox" value="' + data.WebIndustryInfo[i].industryId + '" name="industryId" class="industryItem" checked>' +
                                        '<label>' + data.WebIndustryInfo[i].industryName + '</label>' +
                                        '</span>';
                                    industryUpdate += '<span title="' + data.WebIndustryInfo[i].industryName + '">' +
                                        '<input type="checkbox" value="' + data.WebIndustryInfo[i].industryId + '" name="industryId" class="industryItem">' +
                                        '<label>' + data.WebIndustryInfo[i].industryName + '</label>' +
                                        '</span>';
                                }
                            }
                            fatherBody.find(".industryUpdateBox").html(industryUpdate);
                            fatherBody.find(".industryBox").html(industryHtml);
                            $(".industryBox").html(industryHtml);
                        }
                        /*在遍历data.DataTypeInfo,获取数据范围列表*/
                        if ($("[name=dataRange]").length > 0) {
                            if (data.DataTypeInfo.length > 0) {
                                for (var i = 0; i < data.DataTypeInfo.length; i++) {
                                    dataHtml += '<option value="' + eval(data.DataTypeInfo[i].dataTypeValue) + '">' + data.DataTypeInfo[i].dataTypeName + '</option>'
                                }
                                $("[name=dataRange]").html(dataHtml);
                            }
                        }
                        /*在遍历data.lawState,获取法律状态列表*/
                        if ($(".lawState").length > 0) {
                            if (data.lawState.length > 0) {
                                for (var i = 0, len = data.lawState.length; i < len; i++) {
                                    lawHtml += '<span><input type="checkbox" name="lawState" value="' + data.lawState[i].value + '" checked><label>' + data.lawState[i].name + '</label></span>'
                                }
                                $(".lawState").html(lawHtml);
                            }
                        }
                        /*遍历data.cfgDictionaryInfo,获取权利人类型*/
                        if ($(".cfgDictionaryBox").length > 0) {
                            typeHtml = '<span><input type="checkbox"  class="typeAll" checked><label>全部</label></span>';
                            for (var i = 0; i < data.CfgDictionaryInfo.length; i++) {
                                if (data.CfgDictionaryInfo.length > 0) {
                                    typeHtml += '<span><input type="checkbox" name="type"  class="typeItem" value="' + data.CfgDictionaryInfo[i].value + '" checked><label class="ptmt-collction-s-t-b-lable">' + data.CfgDictionaryInfo[i].name + '</label></span>';
                                }
                            }
                            $(".cfgDictionaryBox").html(typeHtml);
                        }
                    } else {
                        alert(data.msg);
                    }
                }
            })
            var applicantsHtml = '<option value="">全部</option>';
            $.ajax({
                url: window.jkconfig.webapiurlv + "analysis/patentApply/param",
                success: function (data) {
                    if (data.code == 0) {
                        if (data.applicants.length > 0) {
                            for (var i = 0; i < data.applicants.length; i++) {
                                applicantsHtml += '<option value="' + eval(data.applicants[i].value) + '">' + data.applicants[i].name + '</option>'
                            }
                            $("[name=applicants]").html(applicantsHtml);
                        }
                    }
                }
            })
            /*获取专利类型*/
            var obTypeChecked = "";
            if ($("#patType").length > 0) {
                if (!!localStorage["type"] && localStorage["type"] != "") {
                    obTypeChecked = '<span><input type="checkbox" name="type" value="" class="typeAll"><label>全部</label></span>';
                } else {
                    obTypeChecked = '<span><input type="checkbox" name="type" value="" class="typeAll" checked><label>全部</label></span>';
                }
                $.ajax({
                    url: window.jkconfig.webapiurlv + "applychange/param",
                    success: function (data) {
                        if (data.code == 0) {
                            /*遍历data.patTypes,获取区域列表*/
                            if (data.patTypes.length > 0) {
                                for (var i = 0; i < data.patTypes.length; i++) {
                                    if (!!localStorage["type"] && localStorage["type"] != "") {
                                        if (data.patTypes[i].value == localStorage["type"]) {
                                            obTypeChecked += '<span><input type="checkbox" name="patType" value="' + data.patTypes[i].value + '" checked><label class="ptmt-collction-s-t-b-lable">' + data.patTypes[i].name + '</label></span>';
                                        } else {
                                            obTypeChecked += '<span><input type="checkbox" name="patType" value="' + data.patTypes[i].value + '"><label class="ptmt-collction-s-t-b-lable">' + data.patTypes[i].name + '</label></span>';
                                        }
                                    } else {
                                        obTypeChecked += '<span><input type="checkbox" name="patType" value="' + data.patTypes[i].value + '" checked><label class="ptmt-collction-s-t-b-lable">' + data.patTypes[i].name + '</label></span>';
                                    }
                                }
                                $("#patType").html(obTypeChecked);
                                localStorage["type"] = "";
                            }
                        } else {
                            $.showErr("获取专利类型列表失败!");
                        }
                    }
                });
            }
            /*获取失效分析的月份*/
            $.ajax({
                url: window.jkconfig.webapiurlv + "sys/timeranges",
                type: 'GET',
                success: function (data) {
                    if (data.code == 0) {
                        $("#patent-month").html(data.expiredMonths);
                    } else {
                        $.showErr("获取失败!");
                    }
                }
            })
        }
    }
    List.getList();


    $(function () {
        //起始日期
        $("#startDate").click(function () {
            WdatePicker({maxDate: '#F{$dp.$D(\'endDate\')}'});
        });
        $("#endDate").click(function () {
            WdatePicker({minDate: '#F{$dp.$D(\'startDate\')}'});
        });
        $("#shenqingriStart").click(function () {
            WdatePicker({maxDate: '#F{$dp.$D(\'shenqingriEnd\')}'});
        });
        $("#shenqingriEnd").click(function () {
            WdatePicker({minDate: '#F{$dp.$D(\'shenqingriStart\')}'});
        });

        $("#gkrStart").click(function () {
            WdatePicker({maxDate: '#F{$dp.$D(\'gkrEnd\')}'});
        });
        $("#gkrEnd").click(function () {
            WdatePicker({minDate: "#F{$dp.$D(\'gkrStart\')}"});
        })
        // $("#gkrStart").click(function(){ WdatePicker({maxDate:'#F{$db.$D(\'gkrEnd\')}'});})
        // $("#gkrEnd").click(function(){ WdatePicker({minDate:'#F{$db.$D(\'gkrStart\')}'});})
        $("#ssrStart").click(function () {
            WdatePicker({maxDate: "#F{$dp.$D(\'ssrEnd\')}"});
        })
        $("#ssrEnd").click(function () {
            WdatePicker({minDate: "#F{$dp.$D(\'ssrStart\')}"});
        })
        $("#sxrStart").click(function () {
            WdatePicker({maxDate: "#F{$dp.$D(\'sxrEnd\')}"});
        })
        $("#sxrEnd").click(function () {
            WdatePicker({minDate: "#F{$dp.$D(\'sxrStart\')}"});
        })
        $("#shouquanriStart").click(function () {
            WdatePicker({maxDate: "#F{$dp.$D(\'shouquanriEnd\')}"});
        })
        $("#shouquanriEnd").click(function () {
            WdatePicker({minDate: "#F{$dp.$D(\'shouquanriStart\')}"});
        })


        /*问号提示*/
        $(".p-t-question").hover(function () {
            //console.log($(this).offset().top);
            $(".pt-int-content").css("left", $(this).offset().left - 12);
            $(".pt-int-content").css("top", $(this).offset().top + $(this).outerHeight());
            $(".p-i-box").html($(this).attr("data-content"));
            $(".pt-int-content").show();
        }, function () {
            $(".pt-int-content").hide();
        });


        /*全选和单选*/
        $("body").on("click", '.typeAll', function () {
            if (this.checked) {
                $.each($(".typeItem"), function (index, element) {
                    $(element).prop("checked", true);
                })
            } else {
                $.each($(".typeItem"), function (index, element) {
                    $(element).removeAttr("checked", false);
                })
            }
        }).on("click", ".industryAll", function () {
            if (this.checked) {
                $.each($(".industryItem"), function (index, element) {
                    $(element).prop("checked", true);
                })
            } else {
                $.each($(".industryItem"), function (index, element) {
                    $(element).removeAttr("checked", false);
                })
            }
        }).on("click", ".selectAll", function () {
            if (this.checked) {
                $.each($(".checkItem"), function (index, element) {
                    $(element).prop("checked", true);
                })
            } else {
                $.each($(".checkItem"), function (index, element) {
                    $(element).removeAttr("checked", false);
                })
            }
        }).on("click", ".btnClose", function () {
            $(this).closest(".modal").hide();
        })
    })
});
